package com.example.demo.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.common.result.Result;
import com.example.demo.model.entity.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.requestRvo.IDRvo;
import com.example.demo.service.requestRvo.QueryListRVO;
import com.example.demo.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public Result getLIstById(IDRvo vo){
     List<User> user = userMapper.getById(vo.getId());
        System.out.println(user);

        return Result.okSingle(user);
    }

    @Override
    public Result getList(QueryListRVO vo){
        PageHelper.startPage(vo.getPageNumber(),vo.getPageSize());
        QueryWrapper<User> qw = new  QueryWrapper<>();
        qw.eq("user_id",vo.getId());
        List<User> user =userMapper.selectList(qw);
        PageInfo<User> pageInfo = new PageInfo<>(user);
        List<User> list = pageInfo.getList();

        return Result.okSingle(list);
    }

    @Override
    public Result getListAll(QueryListRVO vo){
        PageHelper.startPage(vo.getPageNumber(),vo.getPageSize());
        QueryWrapper<User> qw = new  QueryWrapper<>();
         List<User> user = userMapper.selectList(qw);
        PageInfo<User> pageInfo = new PageInfo<>(user);
        return Result.okPageInfo(pageInfo);
    }
}
